package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.R;

import com.atguigu.eduservice.entity.vo.SubjectNestedVo;
import com.atguigu.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author Sdr
 * @since 2021-09-01
 */
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
@Api(value = "课程分类", tags = "讲师管理接口")
public class EduSubjectController {

    @Autowired
    private EduSubjectService subjectService;

    // 获取上传的文件，将内容读取出来
    // 添加课程
    @ApiOperation(value = "Excel批量导入")
    @PostMapping("addSubject")
    public R addSubject(MultipartFile file){
        // 获取上传过来的Excel文件

        subjectService.saveSubject(file,subjectService);
        return R.ok();
    }

    @ApiOperation(value = "嵌套数据列表")
    @GetMapping("")
    public R nestedList(){

        List<SubjectNestedVo> subjectNestedVoList = subjectService.nestedList();
        return R.ok().data("items", subjectNestedVoList);
    }


}

